from django.shortcuts import render
from django.http import JsonResponse

def chart_list(request):
    """数据统计"""
    return render(request,"chart_list.html")

def chart_bar(request):
    """构造柱状图数据"""

    legend = ["赵XX","钱XX"]
    series_list = [
          {
            "name": '赵XX',
            "type": 'bar',
            "data": [5, 20, 36, 10, 10, 20]
          },
            {
            "name": '钱XX',
            "type": 'bar',
            "data": [3, 10, 26, 15, 20, 25]
          }
        ]

    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月']

    result = {
        "status": True,
        "data": {
            "legend": legend,
            "series_list": series_list,
            "x_axis": x_axis,
        }
    }

    return JsonResponse(result)

def chart_pie(request):
    """饼状图"""
    db_data_list = [
                { "value": 2048, "name": 'IT部' },
                { "value": 735, "name": '新媒体' },
                { "value": 180, "name": '运营' },
              ]

    result = {
        "status": True,
        "data": db_data_list
    }
    return JsonResponse(result)

def chart_line(request):
    """折线图"""
    legend = ["上海", "广州","北京"]
    series_list = [
        {
            "name": '上海',
            "type": 'line',
            "stack": 'Total',
            "data": [15, 20, 36, 10, 10, 20]
        },
        {
            "name": '广州',
            "type": 'line',
            "stack": 'Total',
            "data": [3, 10, 26, 15, 20, 25]
        },
        {
            "name": '北京',
            "type": 'line',
            "stack": 'Total',
            "data": [5, 15, 20, 20, 15, 20]
        }
    ]

    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月']

    result = {
        "status": True,
        "data": {
            "legend": legend,
            "x_axis": x_axis,
            "series_list": series_list,
        }
    }

    return JsonResponse(result)